using System;
using System.IO;
namespace MicroMsg.Common.Utils
{
	public class ImageUtil
	{
		public static void init()
		{
		}
		public static byte[] toPng(byte[] imageBuf)
		{
			return null;
		}
		public static ImageFromat getImageFormat(byte[] imageBuf)
		{
			if (imageBuf.Length >= 2 && imageBuf[0] == 66 && imageBuf[1] == 77)
			{
				return ImageFromat.const_3;
			}
			if (imageBuf.Length >= 6 && imageBuf[0] == 71 && imageBuf[1] == 73 && imageBuf[2] == 70 && imageBuf[3] == 56 && (imageBuf[4] == 57 || imageBuf[4] == 55) && imageBuf[5] == 97)
			{
				return ImageFromat.const_4;
			}
			if (imageBuf.Length >= 8 && imageBuf[0] == 137 && imageBuf[1] == 80 && imageBuf[2] == 78 && imageBuf[3] == 71 && imageBuf[4] == 13 && imageBuf[5] == 10 && imageBuf[6] == 26 && imageBuf[7] == 10)
			{
				return ImageFromat.const_2;
			}
			if (imageBuf.Length >= 11)
			{
				if (imageBuf[6] == 69 && imageBuf[7] == 120 && imageBuf[8] == 105 && imageBuf[9] == 102 && imageBuf[10] == 0)
				{
					return ImageFromat.jpeg;
				}
				if (imageBuf[6] == 74 && imageBuf[7] == 70 && imageBuf[8] == 73 && imageBuf[9] == 70 && imageBuf[10] == 0)
				{
					return ImageFromat.jpeg;
				}
			}
			return ImageFromat.unknown;
		}
		public static bool CheckImageFormat(Stream imgStream)
		{
			if (imgStream == null)
			{
				return false;
			}
			imgStream.set_Position(0L);
			byte[] array = new byte[100];
			imgStream.Read(array, 0, 100);
			ImageFromat imageFormat = ImageUtil.getImageFormat(array);
			imgStream.set_Position(0L);
			return imageFormat == ImageFromat.jpeg || imageFormat == ImageFromat.const_2;
		}
	}
}
